package com.sc.study.foundation.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.sc.study.foundation.service.IScSubjectChapterService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sc.common.annotation.Log;
import com.sc.common.core.controller.BaseController;
import com.sc.common.core.domain.AjaxResult;
import com.sc.common.enums.BusinessType;
import com.sc.study.foundation.domain.ScSubjectChapter;
import com.sc.study.foundation.service.IScSubjectChapterService;
import com.sc.common.utils.poi.ExcelUtil;
import com.sc.common.core.page.TableDataInfo;

/**
 * 课程章节Controller
 * 
 * @author sc
 * @date 2022-03-05
 */
@RestController
@RequestMapping("/study/subjectChapter")
public class ScSubjectChapterController extends BaseController
{
    @Autowired
    private IScSubjectChapterService subjectChapterService;


    /**
     * 查询课程章节列表
     */
    @PreAuthorize("@ss.hasPermi('study:subjectChapter:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScSubjectChapter subjectChapter)
    {
        startPage();
        List<ScSubjectChapter> list = subjectChapterService.selectSubjectChapterList(subjectChapter);
        return getDataTable(list);
    }

    /**
     * 导出课程章节列表
     */
    @PreAuthorize("@ss.hasPermi('study:subjectChapter:export')")
    @Log(title = "课程章节", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScSubjectChapter subjectChapter)
    {
        List<ScSubjectChapter> list = subjectChapterService.selectSubjectChapterList(subjectChapter);
        ExcelUtil<ScSubjectChapter> util = new ExcelUtil<ScSubjectChapter>(ScSubjectChapter.class);
        util.exportExcel(response, list, "课程章节数据");
    }

    /**
     * 获取课程章节详细信息
     */
    @PreAuthorize("@ss.hasPermi('study:subjectChapter:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(subjectChapterService.selectSubjectChapterById(id));
    }

    /**
     * 新增课程章节
     */
    @PreAuthorize("@ss.hasPermi('study:subjectChapter:add')")
    @Log(title = "课程章节", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScSubjectChapter subjectChapter)
    {
        return toAjax(subjectChapterService.insertSubjectChapter(subjectChapter));
    }

    /**
     * 修改课程章节
     */
    @PreAuthorize("@ss.hasPermi('study:subjectChapter:edit')")
    @Log(title = "课程章节", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScSubjectChapter subjectChapter)
    {
        return toAjax(subjectChapterService.updateSubjectChapter(subjectChapter));
    }

    /**
     * 删除课程章节
     */
    @PreAuthorize("@ss.hasPermi('study:subjectChapter:remove')")
    @Log(title = "课程章节", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(subjectChapterService.deleteSubjectChapterByIds(ids));
    }
}
